<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2021/7/29
  Time: 16:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link href="static/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
  <link href="static/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
  <link href="static/css/animate.min.css" rel="stylesheet">
  <link href="static/css/myAlert.css" rel="stylesheet">
  <link href="static/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">
</head>
<body>
<div class="ibox-content MYP" style="margin-left: 5%;margin-top: 5%">
  <h3>项目列表</h3>
  <table class="table table-bordered">
    <thead>
    <tr>
      <th>项目id</th>
      <th>项目名称</th>
      <th>项目编号</th>
      <th>申报单位</th>
      <th>负责人</th>
      <th>项目类型</th>
      <th>开始时间</th>
      <th>结束时间</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody class="PROJECY">
    </tbody>
  </table>
</div>
<div class="ibox-content changeform" style="margin-left: 5%;margin-top: 5%">
  <form class="form-horizontal" action="changeproject" method="post">
    <h2 class="showid">申请变更</h2>
    <input type="hidden" name="pid" class="topid">
    <div class="form-group">
      <label class="col-sm-3 control-label">项目名称：</label>
      <div class="col-sm-8">
        <input type="text" placeholder="项目名称" class="form-control pname" name="pname">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">项目编码：</label>
      <div class="col-sm-8">
        <input type="text" placeholder="项目编码" class="form-control pcode" name="pcode">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">项目类型：</label>
      <div class="col-sm-8">
        <input type="text" placeholder="项目类型" class="form-control ptype" name="ptype">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">项目负责人：</label>
      <div class="col-sm-8">
        <input type="text" placeholder="项目负责人" class="form-control pdirector" name="ppdirector">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">开始时间：</label>
      <div class="col-sm-8">
        <input type="text"  class="form-control  pstart" name="pstart">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label pstart">结束时间：</label>
      <div class="col-sm-8">
        <input type="text"  class="form-control pend" name="pend">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label pstart">变更事项：</label>
      <div class="col-sm-8">
        <select class="form-control" name="pone">
          <option value="punit">申报单位</option>
          <option value="piunit">实施单位</option>
          <option value="pdirector">负责人</option>
          <option value="pphone">联系电话</option>
          <option value="ppostcode">邮政编码</option>
        </select>
      </div>
    </div>
    <div class="form-group">
    <label class="col-sm-3 control-label">新的信息：</label>
    <div class="col-sm-8">
      <input type="text" placeholder="变更内容新的信息" class="form-control pmsg" name="pmsg">
    </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">变更日期：</label>
      <div class="col-sm-8">
        <input type="date"  class="form-control chdate" name="chdate">
      </div>
    </div>
    <div class="form-group">
      <input type="hidden" class="newmsg" name="pid">
      <label class="col-sm-3 control-label">预期成果：</label>
      <div class="col-sm-8">
        <input type="text" placeholder="预期成果" class="form-control chresult" name="chresult">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">变更原因：</label>
      <div class="col-sm-8">
        <input type="text" placeholder="变更原因" class="form-control chreson" name="chreson">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">成员确认：</label>
      <div class="col-sm-8">
        <input type="text" placeholder="成员签名" class="form-control chconfirm" name="chconfirm">
      </div>
    </div>
    <input type="submit" class="btn btn-outline btn-success update no" value="确认修改"/>
    <input type="button" class="btn btn-outline btn-info no" value="取消修改"/>
  </form>
</div>
<script src="static/js/jquery.min.js?v=2.1.4"></script>
<script src="static/js/bootstrap.min.js?v=3.3.5"></script>
<script src="static/js/plugins/iCheck/icheck.min.js"></script>
<script src="static/js/jquery.form.min.js"></script>
<script src="static/js/myAlert.js"></script>
<script>
  $(function (){
    $(".changeform").hide();
    function timestampToTime(timestamp) {
      // var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
      var date = new Date(timestamp)
      Y = date.getFullYear() + '-';
      M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
      D = date.getDate() + ' ';
      h = date.getHours() + ':';
      m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()) + ':';
      s = (date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds());
      return Y+M+D
    }
    $.ajax({
      url:"findMyProject",
      type:"post",
      success:function (data){
        for (let i = 0; i < data.length; i++) {
          $(".PROJECY").append(" <tr><td id='pid'>"+data[i].pid+"</td><td id='pname'>"+data[i].pname+"</td><td id='pcode'>"+data[i].pcode+"</td><td id='punit'>"+data[i].punit+"</td>" +
                  " <td id='pdirector'>"+data[i].pdirector+"</td> <td id='ptype'>"+data[i].ptype+"</td><td id='pstart'>"+timestampToTime(data[i].psdate)+"</td><td id='pend'>"+timestampToTime(data[i].ptdate)+"</td>" +
                  "<td><input type='button' class='btn btn-outline btn-primary' value='申请变更'></td></tr>")
        }
        //申请变更
        $(".btn-primary").click(function (){
          let pid= $(this).parents("tr").find("#pid").text()
          let pname= $(this).parents("tr").find("#pname").text()
          let pcode= $(this).parents("tr").find("#pcode").text()
          let punit= $(this).parents("tr").find("#punit").text()
          let pdirector= $(this).parents("tr").find("#pdirector").text()
          let ptype= $(this).parents("tr").find("#ptype").text()
          let pstart= $(this).parents("tr").find("#pstart").text()
          let pend= $(this).parents("tr").find("#pend").text()
            $(".topid").val(pid)
            $(".pname").val(pname)
            $(".pcode").val(pcode)
            $(".punit").val(punit)
            $(".pdirector").val(pdirector)
            $(".ptype").val(ptype)
            $(".pstart").val(pstart)
            $(".pend").val(pend)
          $('.changeform').show()
          $(".MYP").hide();
          $(".form-horizontal").submit(function (){
            $(this).ajaxSubmit()
            return false;
          })
        })
      }
    })
    var malert= {
      title: "Tip",
      msg: "操作成功",
    }
    $(".update").click(function (){
      MyAlert(malert);
    })
    $(".no").click(function (){
      $('.changeform').hide()
      $(".MYP").show();
    })
  })
</script>
</body>
</html>
